package com.lagou.muticodec;

import com.lagou.util.HexUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class StringDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        byte[] bytes = new byte[in.readableBytes()];
        in.readBytes(bytes);

        System.out.println("Hex.encodeHexString(bytes):"+ HexUtil.bytesToHexString(bytes));
        System.out.println("new String(bytes):"+new String(bytes));

        out.add(new String(bytes));
    }
}
